<!DOCTYPE html>
<HTML lang="en">
<HEAD>
    <title> The Baby X Object </title>
    <meta charset="UTF-8">
        
    <link href="prism.css" rel="stylesheet">
<script src="microlight.js"> </script>
<script src="prism.js"> </script>
<style>
.microlight {
    font-family : monospace;
    white-space : pre;
    background-color : white;
}
    
BODY {
    width:50em;
    margin-left:5em;
    background-color:#c0c0ff;
}

P {
   width : 50em;
}

pre {
   background-color:white;
}
</style>
</HEAD>
<BODY>
<A href="index.html"><IMG src="BabyXLogos/baby-x-logo.svg" alt="Baby X logo" width=50></A>
<H1> The Baby X Object </H1>
<P>
When you start Baby X, it returns an opaque object of type "BABYX"
which represents the connection to the Baby X server. The connection
is needed for creating new Baby X objects and for destroying them,
also for a few object-level functions.
</P>

<P>
<pre><code class="language-c">
    void startbabyx(
    char *name,
    int width,
    int height,
    void (*create)(void *ptr, BABYX *bbx, BBX_Panel *root),
    void (*layout)(void *ptr, int width, int height),
    void *ptr);
    void stopbabyx(BABYX *bbx);
</code></pre>
</P>
<P>
These are the functions for launching and stopping the Baby X server.
startbabyx() never returns until stopbabyx() is called. It takes
the name of the program, to be displayed in the title bar, the width
and height of the top level window requested, the create and layout
callbacks, and the context pointer which is passed back to these functions.
When stopbabyx() is called, it closes the root window, and destroys
the BABYX object.
</P>
<P>
The callbacks create and layout represent the only entry points of
Baby X into the user program. You will get one create call, to which
you should respond by creating top level children off the root panel,
and possibly more than one layout call, to which you should respond
by rearranging the child objects, and possibly redrawing. Note that
you are not guaranteed the same width and height on layout as you 
requested from startbabyx().
</P>
<pre><code class="language-c">
int bbx_setpos(BABYX *bbx, void *obj, int x, int y, int width, int height);
int bbx_setsize(BABYX *bbx, void *obj, int width, int height);
int bbx_getsize(BABYX *bbx, void *obj, int *width, int *height);
int bbx_setfocus(BABYX *bbx, void *obj);
</code></pre>
<P>
These functions take any basic widget created with Baby X, and
access the common header internally. You can set the position
relative to the parent, set the size, get the size, or set
the keyboard focus.
</P>
<pre><code class="language-c">
void *bbx_addticker(BABYX *bbx, int ms_interval, void (*fptr)(void *ptr), void *ptr);
void bbx_removeticker(BABYX *bbx, void *ticker); 
</code></pre>
<P>
Some programs, such as games or animations, are driven by clcok ticks
rather than by user input events. So yu can add a ticker. Baby X
call the tick function with it context pointer, approximately
every tick interval. It's not accurate enought to use for high
resolution timing. When you have done with a ticker, you remove it.
The return value is an opaque void * whose only purpose is to 
be passed back to removeticker().
</P>
<pre><code class="language-c">
void bbx_copytexttoclipboard(BABYX *bbx, char *text);
char *bbx_gettextfromclipboard(BABYX *bbx);
</code></pre>
<P>
Baby X offers a simple interface to the clipboard. Currently 
only text is supported. The string returned from bbx_gettextfromclipboard
should be freed by caller when it is finished with.
</P>
<pre><code class="language-c">
void *bbx_malloc(int size);
void *bbx_realloc(void *ptr, int size);
char *bbx_strdup(const char *str);
</code></pre>
<P>
Bbay X wraps malloc() and realloc() so that these functions never return
null. Currently it exits the program on allocation failure, so only
call for allocations where this is the only sensible response. There's
also a convenience function for duplicating a string.
</P>
<pre><code class="language-c">
int bbx_kbhit(BABYX *bbx, int code);
</code></pre>
<P>
Baby X implements a kbhit. The code is the Baby X key code, which is either
an alphanumeric character, or one of the special keys.
</P>
<pre><code class="language-c">
         BBX_KEY_BACKSPACE
	     BBX_KEY_DELETE
	     BBX_KEY_ESCAPE
	     BBX_KEY_HOME
	     BBX_KEY_LEFT
	     BBX_KEY_UP
	     BBX_KEY_RIGHT
	     BBX_KEY_DOWN 
	     BBX_KEY_END
</code></pre>
<P>
bbx_kbhit() return true if the key is depressed, false if it is not.
It doesn't black waiting for keyboard input. It is used for games or
to control naviagtion via arrow keys.
</P>

</BODY>
</HTML>
